﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Classwork05
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("6-100的整数的哥特巴赫猜想：");
            for(int i = 6; i < 101; i += 2)
            {
                calculateGuess(i);
            }
            
            order();

            Console.ReadLine();
        }

        static bool isPrime(int number)
        {
            if (number % 2 == 0)
                return false;

            for(int i = 3; i <= number / 2; i += 2)
            {
                if (number % i == 0)
                    return false;
            }

            return true;
        }

        static void calculateGuess(int number)
        {
            for(int i = 2; i <= number / 2; i++)
            {
                if (isPrime(i) && isPrime(number - i))
                    Console.WriteLine(number + "=" + i + "+" + (number - i));
            }
        }

        static void order()
        {
            Console.WriteLine("生成一组随机数：");
            Random rnd = new Random();
            int[] vs = new int[100];
            for (int i = 0; i < vs.Length; i++)
            {
                int n = rnd.Next(1000);
                vs[i] = n;
            }

            int j = 0;
            foreach(int i in vs)
            {
                j++;
                Console.Write(i);
                Console.Write("，");
                if (j % 10 == 0)
                    Console.WriteLine();
            }

            Console.WriteLine("将随机数排序：");
            var result1 = vs.OrderByDescending(a => a);
            var result2 = vs.Sum();
            var result3 = vs.Average();

            foreach(int i in result1)
            {
                j++;
                Console.Write(i);
                Console.Write("，");
                if (j % 10 == 0)
                    Console.WriteLine();
            }
            Console.WriteLine("数的和为：");
            Console.WriteLine(result2);
            Console.WriteLine("数的平均值为：");
            Console.WriteLine(result3);
        }
    }
}
